define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;


    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>确定是否提交？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });


    var _vm = Init.initVue({
        data : {
            id: null,
            check: {},
            typeArr: [],
            res: {
                parent_id : 0,
                name: ''
            }
        },
        methods : {
            submit : function() {
                var url,flag;

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                if (_vm.id) {
                    url = "coltype/update";
                    _vm.res.id = _vm.id;
                } else {
                    url = "coltype/create";
                }
                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax(url,{ data: JSON.stringify(_vm.res)},{type : 'post'}).done(function(){
                            METHOD.loading.hide();
                            METHOD.alert("操作成功").done(function(){
                                window.location.href = "../collection/category.html";
                            });
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });
            },
            getType : function() {
                METHOD.loading.show();
                METHOD.ajax("coltype/all_list",{}).done(function(json){
                    METHOD.loading.hide();
                    _vm.typeArr = json.data;

                }).fail(function(){
                    METHOD.loading.hide();
                })
            }
        }
    });

    _vm.id = METHOD.getQueryParms("id") || null;

    if (_vm.id) {
        METHOD.loading.show();
        METHOD.ajax("coltype/detail",{ id: _vm.id }).done(function(json){
            METHOD.loading.hide();
            _vm.res = json.data;
        }).fail(function(){
            METHOD.loading.hide();
        })
    }

    _vm.getType();


});

